package com.wandian.util
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;

	/**
	 * @author long
	 * @Create  2012-10-20 下午03:09:09
	 * @QQ 108232706
	 * @version 1.0
	 */
	public class CLZButton
	{
		private static const UP:uint=1;
		private static const OVER:uint=2;
		private static const DOWN:uint=3;
		private static var _filter:GlowFilterManage=GlowFilterManage.getInstance();

		public function CLZButton()
		{
			return;
		}

		public static function enabled(mcButton:MovieClip, boolButtonMode:Boolean=true, alpha:Number=0.2):void
		{
			if (boolButtonMode)
			{
				mcButton.mouseChildren=false;
				mcButton.mouseEnabled=true;
				mcButton.buttonMode=true;
				mcButton.alpha=1;
				mcButton.filters=[];
			}
			else
			{
				mcButton.mouseChildren=false;
				mcButton.mouseEnabled=false;
				mcButton.buttonMode=false;
				mcButton.alpha=alpha;
				mcButton.filters=_filter.getGrayscale();
			}
			return;
		} 

		public static function setButton(mcButton:MovieClip, txtShow:String="", tipObj:Object=null, boolColor:Boolean=true, arrColors:String=""):void
		{
			mcButton.mouseChildren=false;
			mcButton.buttonMode=true;
			mcButton.mouseEnabled=true;
			mcButton.filters=[];
			mcButton.gotoAndStop(1);
			var arrColor:*=arrColors.split(",");
			mcButton.arrColor=arrColor;
			mcButton.txtMsg=txtShow;
			mcButton.tipObj=tipObj;
			updateTxtAndColor(mcButton);
			if (tipObj != null)
			{
				if (tipObj.pointXY != null)
				{
					mcButton.disX=tipObj.pointXY.disX;
					mcButton.disY=tipObj.pointXY.disY;
				}
				ToolTip.stage=Texas.I._mcTipView.stage;
				ToolTip.setDOInfo(mcButton, tipObj.tip);
			}
			mcButton.addEventListener(MouseEvent.MOUSE_OVER, overHandler);
			mcButton.addEventListener(MouseEvent.MOUSE_OUT, outHandler);
			mcButton.addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
			mcButton.addEventListener(MouseEvent.MOUSE_UP, upHandler);
			return;
		} 

		public static function updateMcText(mcBtn:MovieClip, txtMsg:String=""):void
		{
			mcBtn.txtMsg=txtMsg;
			mcBtn.txt.text=txtMsg;
			return;
		} 

		private static function updateTxtAndColor(mcBtn:MovieClip, color:int=0):void
		{
			if (mcBtn.txtMsg == "")
			{
				return;
			}
			if (mcBtn.txt != null)
			{
				mcBtn.txt.text=mcBtn.txtMsg;
				if (mcBtn.arrColor.length == 3)
				{
					mcBtn.txt.textColor=mcBtn.arrColor[color];
				}
			}

		} 

		public static function removeButton(param1:MovieClip):void
		{
			param1.removeEventListener(MouseEvent.MOUSE_OVER, overHandler);
			param1.removeEventListener(MouseEvent.MOUSE_OUT, outHandler);
			param1.removeEventListener(MouseEvent.MOUSE_DOWN, downHandler);
			param1.removeEventListener(MouseEvent.MOUSE_UP, upHandler);
			return;
		} 

		private static function overHandler(event:MouseEvent):void
		{
			var _loc_2:*=event.currentTarget as MovieClip;
			_loc_2.gotoAndStop(OVER);
			updateTxtAndColor(_loc_2, (OVER - 1));
			if (_loc_2.tipObj != null)
			{
				CLZTiming.setTimingTip(_loc_2.tipObj.time, ToolTip.showToolTip);
			}
			return;
		} 

		private static function outHandler(event:MouseEvent):void
		{
			var _loc_2:*=event.currentTarget as MovieClip;
			_loc_2.gotoAndStop(UP);
			updateTxtAndColor(_loc_2, (UP - 1));
			if (_loc_2.tipObj != null)
			{
				CLZTiming.setTimingTip(0, ToolTip.hideToolTip);
			}
			return;
		} 

		private static function downHandler(event:MouseEvent):void
		{
			var _loc_2:*=event.currentTarget as MovieClip;
			_loc_2.gotoAndStop(DOWN);
			updateTxtAndColor(_loc_2, (DOWN - 1));
			return;
		} 

		private static function upHandler(event:MouseEvent):void
		{
			var _loc_2:*=event.currentTarget as MovieClip;
			_loc_2.gotoAndStop(OVER);
			updateTxtAndColor(_loc_2, (OVER - 1));
			return;
		} 

	}
}
